<?php
/**
 * 博客
 * @author zelome@163.com
 * $Id: index.php 10 2011-02-23 07:01:48Z sbnnest@gmail.com $
 */

require_once('../common.inc.php');

class bklist extends Action
{
	/**
	 * 获取博客列表
	 */
	function doDefault()
	{
		$page = $this->app->page();
		$page->params['template'] = 'content/bklist.tpl';
		
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article');
		$db_r->addField('article_id');
		$db_r->addField('article_title');
		$db_r->addField('article_author');
		$db_r->addField('article_category');
		$db_r->addField('article_reply_count');
		$db_r->addField('article_read_count');
		$db_r->addField('article_time');
		
		$rs = $db_r->getArray();
		$page->value('articleList',$rs);
		
		$db_r->clear();
		$db_r->addTable('tb_article_category');
		$db_r->addField('article_category_id');
		$db_r->addField('article_category_name');
		
		$categorys = $db_r->getArray();
		
		$page->value('articleCategoryList',$categorys);
		$page->value('test','test');
		$page->output();
		
	}
	
	/**
	 * 跳转到添加博客页面
	 */
	function doAddpage()
	{
		$page = $this->app->page();
		$page->params['template'] = 'content/bkadd.tpl';
		
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article_category');
		$db_r->addField('article_category_id');
		$db_r->addField('article_category_serial');
		$db_r->addField('article_category_count');
		$db_r->addField('article_category_name');
		$db_r->addField('article_category_createtime');
		$db_r->addField('article_category_modifytime');
		
		$rs = $db_r->getArray();
		$page->value('articleCategoryList',$rs);
		
		$page->output();
	}
	
	/**
	 * 添加博客
	 */
	function doAdd() {
		$page = $this->app->page();
		$page->params['template'] = 'content/bkadd.tpl';
		
		$title = trim($_POST['title']);
		$author = trim($_POST['author']);
		$category = trim($_POST['category']);
		$partner_desc = trim($_POST['partner_desc']);
		$page = $this->app->page();
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article');
		$db_r->addField('article_id');
		$db_r->addField('article_title');
		$db_r->addField('article_author');
		$db_r->addField('article_category');
		$db_r->addField('article_reply_count');
		$db_r->addField('article_read_count');
		$db_r->addField('article_time');
		$db_r->addField('article_body');
		$db_r->insert(array(
		'article_title' => $title,
		'article_body' => $partner_desc,
		'article_reply_count' => 0,
		'article_read_count' => 0,
		'article_category' => $category,
		'article_author' => $author
		));
		
		$page->output();
	}
	
	/**
	 * 删除博客
	 */
	function doDelete() {
		$article_id = $_GET['article_id'];
		$article_tag_id = $_GET['article_tag_id'];
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article');
		$db_r->addField('article_id');
		$db_r->addWhere('article_id',$article_id);
		$db_r->delete();
		
		
		$page = $this->app->page();
		$page->params['template'] = 'content/bklist.tpl';
		
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article');
		$db_r->addField('article_id');
		$db_r->addField('article_title');
		$db_r->addField('article_author');
		$db_r->addField('article_category');
		$db_r->addField('article_reply_count');
		$db_r->addField('article_read_count');
		$db_r->addField('article_time');
		
		$rs = $db_r->getArray();
		$page->value('articleList',$rs);
		
		$page->output();
	}
	
	/**
	 * 显示博客详细信息
	 */
	function doBkPage() {
		$article_id = $_GET['article_id'];
		$page = $this->app->page();
		$page->params['template'] = 'content/bkpage.tpl';
		$page = $this->app->page();
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article');
		$db_r->addField('article_id');
		$db_r->addField('article_title');
		$db_r->addField('article_author');
		$db_r->addField('article_category');
		$db_r->addField('article_reply_count');
		$db_r->addField('article_read_count');
		$db_r->addField('article_time');
		$db_r->addField('article_body');
		$db_r->addWhere ( 'article_id', $article_id );
		$result = $db_r->getRow ();
		
		$page->value ( 'article', $result );
		$page->value ( 'article_body1', $result['article_title']);
		$page->output();
	}
	
	/**
	 * 跳转到修改博客页面
	 */
	function doBkModify() {
		$article_id = $_GET['article_id'];
		$page = $this->app->page();
		$page->params['template'] = 'content/bkmodify.tpl';
		$page = $this->app->page();
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article');
		$db_r->addField('article_id');
		$db_r->addField('article_title');
		$db_r->addField('article_author');
		$db_r->addField('article_category');
		$db_r->addField('article_reply_count');
		$db_r->addField('article_read_count');
		$db_r->addField('article_time');
		$db_r->addField('article_body');
		$db_r->addWhere ( 'article_id', $article_id );
		$result = $db_r->getRow ();
		
		$page->value ( 'article', $result );
		$page->value ( 'article_body1', $result['article_body']);
		$page->output();
	}
}
											
$app->run();

?>
